import  os

def update_file(img_dir,xml_dir):
    base_path = "D:/资料/CV/video/dataset - 副本/"

    xmls = os.listdir(base_path+xml_dir)
    xml_set=set()
    for xml_name in xmls:
        xml_set.add(xml_name.replace("xml",""))

    imgs = os.listdir(base_path+img_dir)
    img_set = set()
    for img_name in imgs:
        img_set.add(img_name.replace("jpg",""))

    print("在jpg不在xml",len(img_set-xml_set))
    print("在xml不在jpg",len(xml_set-img_set))

    remove_names = img_set - xml_set
    for remove_name in remove_names:
        os.remove(base_path+img_dir+"/"+remove_name+"jpg")

if  __name__ == '__main__':

    update_file('image','xml')